﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.InterceptionExtension;
using Thallo.Configuration;
namespace Thallo {
    public class ServiceMatchingRule : IMatchingRule {
        HashSet<string> _assemblies = new HashSet<string>();

        public ServiceMatchingRule( string assembly ) {
            //foreach (var item in assemblies) {
            //    _assemblies.Add(item);
            //}
            if (!string.IsNullOrEmpty(assembly))
                _assemblies.Add(assembly);

            foreach (var item in ThalloSection.Current.Assemblies.Cast<AssemblyElement>()) {
                if (!string.IsNullOrWhiteSpace(item.Name))
                    _assemblies.Add(item.Name);
            }
        }

        public bool Matches(System.Reflection.MethodBase member) {
            string assembly = member.Module.Name;
            assembly = assembly.Substring(0, assembly.Length - 4);
            //assembly = assembly.Substring(0, assembly.Length - 4);
            return _assemblies.Contains(assembly);
        }
    }
}
